/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package poo.biblioteca.vistas.autores;

import biblioteca.entidades.Autor;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import javax.swing.JOptionPane;

/**
 *
 * @author apo
 */
public class DlgBuscarAutor extends javax.swing.JDialog {

    /**
     * Creates new form DlgBuscarAutor
     */
    public DlgBuscarAutor(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        chkBuscarPorNombre = new javax.swing.JCheckBox();
        chkBuscarPorApellido = new javax.swing.JCheckBox();
        txtNombreAutor = new javax.swing.JTextField();
        txtApellidoAutor = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
        scpResultados = new javax.swing.JScrollPane();
        tblResultados = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Buscar Autor");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Búsqueda"));

        chkBuscarPorNombre.setText("Nombre del Autor:");

        chkBuscarPorApellido.setSelected(true);
        chkBuscarPorApellido.setText("Apellido del Autor:");

        txtNombreAutor.setEnabled(false);

        btnBuscar.setMnemonic('B');
        btnBuscar.setText("Buscar");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(chkBuscarPorNombre)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNombreAutor, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(chkBuscarPorApellido)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtApellidoAutor)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnBuscar)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chkBuscarPorNombre)
                    .addComponent(txtNombreAutor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chkBuscarPorApellido)
                    .addComponent(txtApellidoAutor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        scpResultados.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultados"));

        tblResultados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        scpResultados.setViewportView(tblResultados);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(scpResultados, javax.swing.GroupLayout.PREFERRED_SIZE, 388, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scpResultados, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JCheckBox chkBuscarPorApellido;
    private javax.swing.JCheckBox chkBuscarPorNombre;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane scpResultados;
    private javax.swing.JTable tblResultados;
    private javax.swing.JTextField txtApellidoAutor;
    private javax.swing.JTextField txtNombreAutor;
    // End of variables declaration//GEN-END:variables

    public void btnBuscarAddActionListener(ActionListener actionListener) {
        btnBuscar.addActionListener(actionListener);
    }

    public boolean estaSeleccionadoCheckBoxBuscarPorNombre() {
        return chkBuscarPorNombre.isSelected();
    }

    public boolean estaSeleccionadoCheckBoxBuscarPorApellido() {
        return chkBuscarPorApellido.isSelected();
    }
    
    public String getNombreAutor() {
        return txtNombreAutor.getText();
    }
    
    public String getApellidoAutor() {
        return txtApellidoAutor.getText();
    }

    public void setTableModel(TbmAutor tbmAutor) {
        tblResultados.setModel(tbmAutor);
    }

    public void mostrarMensajeError(String message, String titulo) {
        JOptionPane.showMessageDialog(null, message, titulo, JOptionPane.ERROR_MESSAGE);
    }

    public void tblResultadosAddMouseListener(MouseAdapter mouseAdapter) {
        tblResultados.addMouseListener(mouseAdapter);
    }
    
    public Autor getAutorSeleccionado() {
        return ((TbmAutor) tblResultados.getModel()).getAutorEnFila(tblResultados.getSelectedRow());
    }
}
